<?php
include("connect.php");
?>
<?php
$css = '<link rel="stylesheet" type="text/css" media="all" href="asset/css/class_requestedbook.css"><script type="text/javascript" src="asset/js/jquery-1.4.2.min.js"></script>';
$css .= '<link rel="stylesheet" type="text/css" media="all" href="asset/css/paging.css">';

$title = 'Requested Book';
$page_name = 'requested_book';
$page = 1;
?>

<?php
$sql = "select user_category from m_user where user_id=".$_SESSION['userid'];
$retval = mysql_query( $sql, $con );
while($row = mysql_fetch_array($retval))
	{
		$user_category = $row[0];
	}
if(isset($_SESSION["userid"]))
	{
		if($user_category ==9)
		{
			include("header_loggedinadmin.php");
		}else
		{
			include("header_loggedin.php");
		}
	}
else
{
	include("header.php");
}?>

<?php
//paging

	$targetpage = $page_name.".php"; 	
	$limit = 9; 
	$query = "select count(*) from t_request_book a";
                		$query .= " inner join m_book b on a.book_id = b.book_id";
                		$query .= " inner join m_user c on c.user_id = a.user_id ";
                		$query .= " where  a.is_get=0";
                		
     		
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result))
	{
		$total_pages =$row[0];
	}
	//$total_pages = mysql_fetch_array(mysql_query($query));
	//$total_pages = $total_pages[num];
	$stages = 3;
	$page = mysql_escape_string($_GET['page']);
	if($page){
		$start = ($page - 1) * $limit; 
	}else{
		$start = 0;	
		}	
    // Get page data
	$query1 = "select c.fname,c.lname, b.book_title,b.book_author,b.isbn,a.user_id,a.request_book_id,c.phonenumber,c.twitter_account from t_request_book a";
                		$query1 .= " inner join m_book b on a.book_id = b.book_id";
                		$query1 .= " inner join m_user c on c.user_id = a.user_id ";
                		$query1 .= " where  is_get=0";
                		
                  		$query1 .= " LIMIT $start, $limit";
               
	$result = mysql_query($query1);
	
	// Initial page num setup
	if ($page == 0){$page = 1;}
	$prev = $page - 1;	
	$next = $page + 1;							
	$lastpage = ceil($total_pages/$limit);		
	$LastPagem1 = $lastpage - 1;	
	
	$paginate = '';
	include("paging.php");
?>


<div id="blue_bg">
	<div id="main">
        <div class="wrapper">
        	<div id="content">
            	<div id="white_box">
                	<h3 class="flag_long">REQUESTED BOOKS</h3>
                	<?php
                		
						$count=1;		
						while($row = mysql_fetch_array($result))
						{
							$name = $row[0]." ".$row[1];
							$title = $row[2];
							$author = $row[3];
							$isbn = $row[4];
							$userid = $row[5];
							$requestbookid = $row[6];
							$phone = $row[7];
							
							if($count == 3 || $count == 6 || $count == 9)
							{
								echo '<div class="box_330px_nopadding">';
							}else
							{
								echo '<div class="box_330px">';
							}
                        	echo '<div class="book_thumb">';
                           	echo '<img src="images/book_to_sale/book-example.jpg"  />';
                          
                       		echo '</div>';     
                       		echo '<div class="book_column">';	 
                            echo '<a href="request_book_detail.php?requestbookid='.$requestbookid.'&type=request">'.$title.'</a><br />';		
                            echo 'Author <span class="bold">'.$author.'</span><br />';		
                            echo 'Uploader <span class="italic"><a href="my_profile.php?userprofileid='.$userid.'">'.$name.'</a></span><br />';		 						echo 'Phone Number <span class="bold">'.$phone.'</span><br />';	
                            echo '</div>';	
                       		echo '<div class="clear"></div>';	
                    		echo '</div>';
                    		$count+=1;
                    		
						}
						echo '<div class="clear"></div>';
						echo $paginate;
             		?>
           		</div>
            </div>
        </div>
    </div>
</div>
<?php
include("footer.php");
?>
